package com.ruoyi.web.controller.check;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.check.domain.Vacate;
import com.ruoyi.check.service.IVacateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 请假管理Controller
 * 
 * @author tza
 * @date 2023-03-06
 */
@RestController
@RequestMapping("/check/vacate")
public class VacateController extends BaseController
{
    @Autowired
    private IVacateService vacateService;

    /**
     * 查询请假管理列表
     */
    @PreAuthorize("@ss.hasPermi('check:vacate:list')")
    @GetMapping("/list")
    public TableDataInfo list(Vacate vacate)
    {
        System.out.println("请假类型"+vacate.getAbStyel());
        startPage();
        List<Vacate> list = vacateService.selectVacateList(vacate);
        return getDataTable(list);
    }

    /**
     * 导出请假管理列表
     */
    @PreAuthorize("@ss.hasPermi('check:vacate:export')")
    @Log(title = "请假管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Vacate vacate)
    {
        List<Vacate> list = vacateService.selectVacateList(vacate);
        ExcelUtil<Vacate> util = new ExcelUtil<Vacate>(Vacate.class);
        util.exportExcel(response, list, "请假管理数据");
    }

    /**
     * 获取请假管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('check:vacate:query')")
    @GetMapping(value = "/{abId}")
    public AjaxResult getInfo(@PathVariable("abId") Integer abId)
    {
        return success(vacateService.selectVacateByAbId(abId));
    }

    /**
     * 新增请假管理
     */
    @PreAuthorize("@ss.hasPermi('check:vacate:add')")
    @Log(title = "请假管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Vacate vacate)
    {
        return toAjax(vacateService.insertVacate(vacate));
    }

    /**
     * 修改请假管理
     */
    @PreAuthorize("@ss.hasPermi('check:vacate:edit')")
    @Log(title = "请假管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Vacate vacate)
    {
        return toAjax(vacateService.updateVacate(vacate));
    }

    /**
     * 删除请假管理
     */
    @PreAuthorize("@ss.hasPermi('check:vacate:remove')")
    @Log(title = "请假管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{abIds}")
    public boolean remove(@PathVariable Integer[] abIds)
    {
//         String s = Arrays.toString(abIds);
//        System.out.println("删除id---"+s);

        //return toAjax(vacateService.deleteVacateByAbIds(abIds));
        return vacateService.deleteVacateByAbIds(abIds);
    }
}
